<!--
 * @Author: xiaotiwen
 * @Date: 2020-05-18 17:45:32
 * @LastEditTime: 2020-07-07 18:48:20
 * @LastEditors: xiaotiwen
 * @FilePath: \eduweb\src\views\practiceManagement\practiceReworkManagement\reworkAudit.vue
 * @Description: 实践审核页面
 -->
<template>
    <div class="reworkAudit">
        <div class="reworkAudit_one">
            <h2>{{$t('dispersionPracticeApply.title.pageTitle')}}</h2>
            <wordTable :data="data" :label="label" />
            <div class="reworkAudit_two_btns">
                <el-button v-if="type === 'details'" @click="cancel">{{$t('message.return')}}</el-button>
            </div>
        </div>
        <div v-if="type !== 'details'" class="reworkAudit_two">
            <div class="reworkAudit_two_form">
                <h2>{{$t('message.check')}}</h2>
                <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                    <el-row>
                        <el-form-item :label="$t('practiceManagement.opinion')" props="content">
                            <el-input
                                v-model="form.content"
                                maxlength="200"
                                :rows="4"
                                :placeholder="$t('fundingManagement.tips.plzInput')"
                                type="textarea"
                                resize="none"
                            />
                        </el-form-item>
                    </el-row>
                </el-form>
            </div>
            <div class="reworkAudit_two_btns">
                <el-button
                    type="primary"
                    class="reworkAudit_two_btn1"
                    @click="pass"
                >{{$t('message.pass')}}</el-button>
                <el-button type="danger" @click="rejects">{{$t('message.reject')}}</el-button>
                <el-button @click="cancel">{{$t('message.cancel')}}</el-button>
            </div>
        </div>
        <div class="reworkAudit_three">
            <el-collapse accordion>
                <el-collapse-item>
                    <template slot="title">{{$t('practiceManagement.reviewProgress')}}</template>
                    <el-table :data="data1">
                        <el-table-column
                            align="center"
                            width="55"
                            type="index"
                            :label="$t('message.order')"
                        />
                        <el-table-column
                            v-for="(item, idx) in label1"
                            :min-width="item.width"
                            :key="idx"
                            :label="item.label"
                            :prop="item.props"
                            align="center"
                        />
                        <el-table-column prop="result" width="100" :label="$t('message.operating')">
                            <template slot-scope="scope">
                                <el-tag
                                    :type="fieldChange(auditStatus, scope.row.result, ['types', 'value'])"
                                >{{ fieldChange(auditStatus, scope.row.result) }}</el-tag>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item>
            </el-collapse>
        </div>
    </div>
</template>

<script>
import wordTable from '../common/wordTable'
import { getDetail } from 'common/src/api/practiceManagement/practiceReworkManagement'
import { approvalThrough, approvalReject, approvelDetail } from 'common/src/api/approval'
import commonMixins from '../commonMixins'
export default {
    // 组件名称
    name: 'ReworkAudit',
    // 局部注册的组件
    components: {
        wordTable
    },
    mixins: [commonMixins],
    // 组件参数 接收来自父组件的数据
    props: {
        type: {
            type: String,
            default: ''
        },
        ids: {
            type: String,
            default: ''
        },
        dataInfo: {
          type: Object,
          default: {}
        },
        fromCheckDetail:{
          type: Boolean,
          required: false
        },
    },
    // 组件状态值
    data() {
        return {
            form: {
                // compus: '', // 校区
                // courseTeacher: '', // 上课教师
                // courseDateStart: '', // 上课开始时间
                // courseDateEnd: '', // 上课结束时间
                // courseAddr: '', // 上课地点
                content: '' // 审核意见
            },
            data: {}, // 数据类型
            label: [],
            label2: [
                [
                    { label: this.$t('label.stuCode'), props: 'studentNo' },
                    { label: this.$t('label.stuName'), props: 'studentName' }
                ],
                [
                    { label: this.$t('label.college'), props: 'acdemyName' },
                    { label: this.$t('label.major'), props: 'majorName' }
                ],
                [
                    { label: this.$t('label.grade'), props: 'grade' },
                    {
                        label: this.$t('practiceReworkManagement.label.applyCourse'),
                        props: 'courseName'
                    }
                ],
                [
                    {
                        label: this.$t('practiceReworkManagement.label.applyReason'),
                        props: 'applyReason'
                    }
                ],
                [
                    {
                        label: this.$t('practiceReworkManagement.label.files'),
                        props: 'attachName',
                        type: 'file'
                    }
                ]
            ],
            label3: [
                [
                    { label: this.$t('label.stuCode'), props: 'studentNo' },
                    { label: this.$t('label.stuName'), props: 'studentName' }
                ],
                [
                    { label: this.$t('label.college'), props: 'acdemyName' },
                    { label: this.$t('label.major'), props: 'majorName' }
                ],
                [
                    { label: this.$t('label.grade'), props: 'grade' },
                    {
                        label: this.$t('practiceReworkManagement.label.applyCourse'),
                        props: 'courseName'
                    }
                ],
                [
                    {
                        label: this.$t('practiceReworkManagement.label.applyReason'),
                        props: 'applyReason'
                    }
                ],
                [
                    {
                        label: this.$t('practiceReworkManagement.label.files'),
                        props: 'attachName',
                        type: 'file'
                    }
                ]
            ],
            data1: [],
            label1: [
                { label: this.$t('paperBlindTrial.tiemName'), props: 'times', width: 200 },
                { label: this.$t('achievementApply.approvorName'), props: 'approvorName', width: 100 },
                { label: this.$t('academicApply.role'), props: 'role', width: 80 },
                { label: this.$t('achievementApply.explanation'), props: 'content', width: 250 }
            ],
            rules: {},
            options: {
                compus: []
            }
        }
    },
    // 计算属性
    computed: {},
    // 侦听器
    watch: {},
    /**
     * 在实例初始化之后，组件属性计算之前，如data属性等
     */
    created() {},
    /**
     * 在挂载开始之前被调用：相关的 render 函数首次被调用。
     */
    mounted() {

        if(this.dataInfo&&this.dataInfo.no){
          this.form=this.dataInfo.content;
          this.data=this.dataInfo.content;
          this.data.workFlowId=this.dataInfo.no;
          this.data1 = this.dataInfo.listApproveHistory;
          this.data1.forEach(item => {
              if (item.time) {
                  this.$set(
                      item,
                      'times',
                      this.formatDate(new Date(item.time), 'yyyy-MM-dd hh:mm:ss')
                  )
              }
          })
        }else{
          this.getDetails()
        }
        if (this.type === 'details') {
          this.label = this.label3
        } else {
            this.label = this.label2
        }
        this.initOptions({ X_XQ: 'compus' })
    },
    // 组件方法
    methods: {
        cancel() {
            if(this.dataInfo.wfType==137){
              this.$router.go(-1);
            }else{
               this.$emit('cancel')
            }

        },
        // 通过
        pass() {
            this.$eduConfirm(
                this.$t('dispersionPracticeApply.tips.confirmPass'),
                this.$t('message.check')
            ).then(() => {
                // let flag = this.timeChange()
                this.$refs.form.validate(valid => {
                    if (valid) {
                        let params = {
                            content: this.form.content,
                            no: this.data.workFlowId,
                            approveAttachment: [],
                            oaNo: this.data.workFlowId,
                            remark: null,
                            callbackEachTime: true
                        }
                        // if (this.type === 'auditFculty') {
                        //     let forms = JSON.parse(JSON.stringify(this.form))
                        //     let teacher = this.form.courseTeacher
                        //     this.$set(
                        //         forms,
                        //         'courseTeacher',
                        //         `${teacher.name}(${teacher.code})-${teacher.facultyI18n}`
                        //     )
                        //     Object.assign(params, { dataProcess: [forms] })
                        // }
                        approvalThrough(params).then(res => {
                            if (res && res.code !== 200) {
                                this.$message({ message: res.msg, type: 'warning' })
                                return
                            }
                            this.$emit('cancel', 'refresh')
                            this.$message({
                                message: this.$t('practiceManagement.tips.checkSuc'),
                                type: 'success'
                            })
                        })
                    }
                })
            })
        },
        // 驳回
        rejects() {
            this.$confirm(
                this.$t('dispersionPracticeApply.tips.areYouSureReject'),
                this.$t('message.prompt'),
                {
                    confirmButtonText: this.$t('message.confirm'),
                    cancelButtonText: this.$t('message.cancel'),
                    type: 'warning'
                }
            ).then(() => {
                // let flag = false
                if (!this.form.content) {
                    this.$message.warning(this.$t('dispersionPracticeApply.tips.rejectContent'))
                    return;
                }
                // else {
                //     flag = this.timeChange()
                // }
                // if (!flag) {
                    let params = {
                        content: this.form.content,
                        no: this.data.workFlowId,
                        approveAttachment: [],
                        oaNo: this.data.workFlowId,
                        remark: null,
                        callbackEachTime: true
                    }
                    approvalReject(params).then(res => {
                        if (res && res.code !== 200) {
                            this.$message({ message: res.msg, type: 'warning' })
                            return
                        }
                        this.$emit('cancel', 'refresh')
                        this.$message({
                            message: this.$t('dispersionPracticeApply.tips.rejectSuc'),
                            type: 'warning'
                        })
                    })
                // }
            })
        },
        // 获取详情
        getDetails() {
            getDetail({ id: this.ids }).then(res => {
                if (res.data.workFlowId) {
                    this.approvelDetails(res.data.workFlowId)
                }
                this.data = res.data
                this.$set(
                    this.data,
                    'attachName',
                    this.data.udgPtAttachTs.length > 0 ? this.data.udgPtAttachTs[0].attachName : ''
                )
                this.$set(
                    this.data,
                    'attachPath',
                    this.data.udgPtAttachTs.length > 0 ? this.data.udgPtAttachTs[0].attachPath : ''
                )
                // if (this.type === 'auditSchool') {
                //     for (const key in this.form) {
                //         if (this.form.hasOwnProperty(key)) {
                //             this.form[key] = this.data[key]
                //         }
                //     }
                // }
            })
        },
        // 获取工作流详情
        approvelDetails(id) {
            approvelDetail({ no: id }).then(res => {
                this.data1 = res.data.listApproveHistory
                this.data1.forEach(item => {
                    if (item.time) {
                        this.$set(
                            item,
                            'times',
                            this.formatDate(new Date(item.time), 'yyyy-MM-dd hh:mm:ss')
                        )
                    }
                })
            })
        },
        // timeChange() {
        //     // 时间校验
        //     if (this.form.courseDateStart && this.form.courseDateEnd) {
        //         let start = new Date(this.form.courseDateStart).getTime()
        //         let end = new Date(this.form.courseDateEnd).getTime()
        //         if (start > end) {
        //             this.$message({
        //                 type: 'warning',
        //                 message: this.$t('dispersionPracticeApply.tips.timeCheck')
        //             })
        //             return true
        //         }
        //     }
        // }
    }
}
</script>
<style lang="scss" scoped>
.reworkAudit {
    &_one {
        padding: 20px;
        background-color: #fff;
        h2 {
            font-weight: bold;
            font-size: 16px;
        }
    }
    &_two {
        margin-top: 20px;
        background-color: #fff;
        h2 {
            font-weight: bold;
            font-size: 16px;
        }
        &_form {
            padding: 20px;
        }
        &_btns {
            padding: 20px;
            border-top: solid #ccc 1px;
            display: flex;
            flex-direction: row-reverse;
        }
        &_btn1 {
            margin-left: 10px;
        }
    }
    &_three {
        padding: 20px;
        margin-top: 20px;
        background-color: #fff;
    }
}
</style>
